<template>
	<view class="home">
		<!-- 顶部 -->
		<block v-if="swiperif">
			<headers :colors="colors" :locations="locations" :swiperList="swiperList"></headers>
		</block>		
		<!-- 推荐分类菜单 与tab分类中不同 -->
		<block v-if="cateif"><classList :categoryList="categoryList"></classList></block>		
		<!-- 公告 -->
		<!-- <notice :colors="colors" :noticeList="noticeList"></notice> -->
		<!-- 栏目 -->
		<!-- <column></column> -->
		<!-- 广告图 -->
		<!-- <banner></banner> -->
		<!-- 热门标题 -->
		<hotstitle :colors="colors"></hotstitle>
		<!-- 推荐商品列表 -->
		<block v-if="dlistif">
			<recommend :colors="colors" :dataList="dataList" :loading="loading" :bottoms="bottoms"></recommend>
		</block>		
		<!-- 右侧悬浮菜单栏 -->
		<suspension :scrollShow="scrollShow" :colors="colors"></suspension>
	</view>
</template>

<script>
	var app = getApp();
	import headers from '../../commponent/home/header';
	import classList from '../../commponent/home/classList';
	import notice from '../../commponent/home/notice';
	import column from '../../commponent/home/column';
	import banner from '../../commponent/home/banner';
	import hotstitle from '../../commponent/home/hotstitle';
	import recommend from '../../commponent/home/recommend';
	import suspension from '../../commponent/home/suspension';
	import {
		getlocation,
		getCart,
		getUserInfo
	} from '@/utils/auth.js'
	export default {
		data() {
			return {
				swiperif:false,
				dlistif:false,
				cateif:false,
				colors: '',
				bottoms: '100',
				scrollShow: false, //是否显示悬浮菜单
				categoryList:[],//分类列表
				// 商品列表
				dataList:[],
				locations: {

				},
				loading: true,
				swiperList:[],
				swiperList: [],
				noticeList:[],
				noticeList: []
			};
		},
		components: {
			headers,
			classList,
			notice,
			column,
			banner,
			hotstitle,
			recommend,
			suspension
		},
		created(){				
			this.myrequest('data/api.data/getSlider').then(res=>{				
				if(res.code==1){					
					this.swiperList=res.data
					this.swiperif=true
				}
			})
			this.myrequest('data/api.goods/getGoods',{},'POST').then(res=>{
				if(res.code==1){
					this.dataList=res.data.list
					this.dlistif=true
				}
			})
			this.myrequest('data/api.goods/getCate',{},'GET').then((res)=>{				
					  if(res.code==1){
						  this.categoryList=res.data
						  this.cateif=true
					  }
			})			
		},
		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad: function(options) {
			// #ifdef APP-PLUS
			this.bottoms = '0'  //在APP下 规格弹窗的位置发生变化
			// #endif
		},

		/**
		 * 生命周期函数--监听页面初次渲染完成
		 */
		onReady: function() {},

		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow: function() {
			//修改购物图标数量
			if(getUserInfo()){
				this.$store.dispatch({
					type:'cartleng',
					uid:getUserInfo().uid
				});					
			}			
			this.setData({
				colors: app.globalData.newColor
			});
			uni.setNavigationBarColor({ //设置标题栏颜色
				backgroundColor: app.globalData.newColor,
				frontColor: '#ffffff'
			});
			// #ifdef H5
			let locations = getlocation() //获取位置信息
			if (locations) {
				this.locations = locations
			}
			// #endif
		},

		/**
		 * 生命周期函数--监听页面隐藏
		 */
		onHide: function() {},

		/**
		 * 生命周期函数--监听页面卸载
		 */
		onUnload: function() {},

		/**
		 * 页面相关事件处理函数--监听用户下拉动作
		 */
		onPullDownRefresh: function() {},

		/**
		 * 页面上拉触底事件的处理函数
		 */
		onReachBottom: function() {
			if (this.dataList.length >= 30) { //模拟上拉加载数据
				this.loading = false
				return
			}
			let data = this.dataList;
			setTimeout(() => {
				this.loading = true
				this.dataList.push(...data);
			}, 500)
		},

		/**
		 * 用户点击右上角分享
		 */
		onShareAppMessage: function() {},
		methods: {
			onPageScroll: function(e) {
				if (e.scrollTop >= 500) {
					this.setData({
						scrollShow: true
					});
				} else {
					this.setData({
						scrollShow: false
					});
				}
			}
		}
	};
</script>
<style scoped lang="scss">
	.home {
		margin-bottom: 40rpx;
	}
</style>
